package com.woniu.day8.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.day8.pojo.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo> {
    @Select("select * from userinfo ${ew.customSqlSegment}")
    @Results(value = {
            @Result(id = true, column = "id", property = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "password", column = "password"),
            @Result(property = "type", column = "type"),
            @Result(property = "imgpath", column = "imgPath"),
            @Result(property = "isdelete", column = "isdelete"),
            @Result(property = "remarks", column = "remarks"),
            @Result(property = "roles", column = "id",
                    many = @Many(select = "com.woniu.day8.mapper.RoleMapper.queryRoleByUid"))
    })
    List<UserInfo> queryUsers(IPage<UserInfo> page, @Param("ew") QueryWrapper<UserInfo> wrapper);
    /**
     * 实现用户登录操作
     */
    @Select("select * from userinfo where username=#{param1} and password=#{param2}")
    UserInfo queryUsernameAndPwd(String username, String password);

    /**
     * 根据用户名修改头像
     */
    @Update("update userinfo set imgPath=#{param2} where username=#{param1}")
    void updateAvatarByUsername(String username, String avatar);
}
